﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace VirtualTournaments.Business.Tests.ServicesTests
{
	public class DatabaseTestHelper
	{

		public static void InsertTeams(SqlConnection connection)
		{
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Argentinos')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Arsenal')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Atlético Tucumán')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Banfield')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Boca')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Chacarita')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Colón')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Estudiantes')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Gimnasia')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Godoy Cruz')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Huracán')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Independiente')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Lanús')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Newells')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Racing')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('River')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Rosario Central')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('San Lorenzo')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Tigre')");
			ExecuteSql(connection, @"INSERT INTO Teams (Name) VALUES ('Vélez')");
		}

		public static void DeleteAll(SqlConnection connection)
		{
			ExecuteSql(connection, @"DELETE FROM BetsTargetsBets;");
			ExecuteSql(connection, @"DELETE FROM ThreeWaysBetsTargets;");
			ExecuteSql(connection, @"DELETE FROM TournamentPodiumBetsTargets;");
			ExecuteSql(connection, @"DELETE FROM BetsTargets;");
			ExecuteSql(connection, @"DELETE FROM BetsTypes;");
			ExecuteSql(connection, @"delete from Accounts");
			ExecuteSql(connection, @"delete from Bets");
			ExecuteSql(connection, @"delete from Users");

			ExecuteSql(connection, @"DELETE FROM JourneysMatches;");
			ExecuteSql(connection, @"DELETE FROM Matches;");
			ExecuteSql(connection, @"DELETE FROM Standings;");
			ExecuteSql(connection, @"delete from Journeys");
			ExecuteSql(connection, @"delete from TournamentsTeams");
			ExecuteSql(connection, @"DELETE FROM Tournaments;");
			ExecuteSql(connection, @"delete from Teams");
			ExecuteSql(connection, @"delete from Players");
		}


		private static void ExecuteSql(SqlConnection connection, string sql)
		{
			using (SqlCommand command = connection.CreateCommand())
			{
				command.CommandType = CommandType.Text;
				command.CommandText = sql;
				command.ExecuteNonQuery();
			}
		}
	}

	//ExecuteSql(connection, String.Format(
	//        @"DELETE FROM Stantings WHERE UserId = {0};",
	//        xx
	//    ););
}
